<template>
  <!-- // 分配角色 -->
  <div>
    这里将来会放置多选列表=={{ roleIds }}
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in rolesList" :key="item.id" :label="item.id"
        >{{ item.name }}====={{ item.id }}</el-checkbox
      >
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="roleHandle">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRolesListApi } from '@/api/settings'
import { getUserDetailById } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    empId: {
      type: String
    }
  },
  data() {
    return {
      rolesList: [],
      paramsObj: {
        page: 1,
        pagesize: 80
      },
      roleIds: []
    }
  },
  created() {
    this.getRoles()
  },
  methods: {
    closeDialog() {
      this.$emit('close')
    },
    async getRoles() {
      const res = await getRolesListApi(this.paramsObj) //  获取total
      // const res2 = await getRolesListApi({ page: 1, pagesize: res.data.total }) //  获取所有的角色
      console.log(res, 777)
      this.rolesList = res.data.rows

      const res2 = await getUserDetailById(this.empId)
      console.log(res2, 99)
      this.roleIds = res2.data.roleIds
    },

    async roleHandle() {
      const res = await assignRoles({
        id: this.empId,
        roleIds: this.roleIds
      })
      // 关闭对话框
      this.closeDialog()
    }
  }
}
</script>